#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_SIZE 32

typedef struct {
    int data[MAX_SIZE];
    int top;
}sqstack_t;

sqstack_t* sqstack_init() {
    sqstack_t* s = (sqstack_t*)malloc(sizeof(sqstack_t));
    memset(s->data,0,sizeof(s->data));
    s->top = -1;
    return s;
}

int sqstack_isfull(sqstack_t *s) {
    return (s->top == MAX_SIZE -1 );
}

int sqstack_isempy(sqstack_t *s) {
    return (s->top == -1);
}

int sqstack_push(sqstack_t *s,int value) {
    if(sqstack_isfull(s)) {
        printf("man");
        return -1;
    }
    s->top++;
    s->data[s->top] = value;
    return 0;
}

int sqstack_pop(sqstack_t *s,int *pvalue) {
    if(sqstack_isempy(s)) {
        printf("kong");
        return -1;
    }
    *pvalue = s->data[s->top];
    s->top--;
    return 0;
}

int main() {
    sqstack_t *s = sqstack_init();
    printf("ru:");
    for(int i = 0; i <= MAX_SIZE; i++) {
        if(sqstack_push(s,i+1)>=0) {
            printf("%d ",i+1);
        }
    }
    printf("\n");
    printf("chu:");
    for(int i = 0; i <= MAX_SIZE; i++) {
        int value;
        if(sqstack_pop(s,&value)>=0) {
            printf("%d ",value);
        }
    }
    printf("\n");
    return 0;
}